package com.tcode.utils;

import java.util.List;

public class Page<T> {
	//当前页码
	private int pageNo;
	//每页显示的记录   初始为每页显示10条记录
	private int pageSize = 10;
	//索引
	private int indexNo;
	
	
	
	

	public void setIndexNo(int indexNo) {
		this.indexNo = indexNo;
	}

	public Page(int pageNo, int pageSize) {
		
		this.pageNo = pageNo;
		
		if(pageSize >0){
				this.pageSize = pageSize;
		}
	}
	public int getIndexNo() {
		return (pageNo-1)*pageSize;//3-1;result*5;=10;
	}

	//定义每页展示的内容集合
	private List<T> list;
	
	//总页数
	private int totalPage;
	
	//总记录数
	private int totalNum;

	public int getPageNo() {
		return pageNo;
	}

	//验证请求的页面上方合法。
	public void setPageNo(int pageNo) {
		if(pageNo <= 0){
			pageNo = 1;
		}else if(pageNo > getTotalPage()){
			pageNo = getTotalPage();
		}
		this.pageNo = pageNo;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public List<T> getList() {
		return list;
	}

	public void setList(List<T> list) {
		this.list = list;
	}

	//总页数
	public int getTotalPage() {
		totalPage = totalNum/pageSize;
		
		if(totalNum % pageSize != 0 ){
			totalPage++;
		}
//		System.out.println(totalPage);
		return totalPage;
	}


	

	public Page(int pageNo) {		
		this.pageNo = pageNo;
	}

	public long getTotalNum() {
		return totalNum;
	}

	public void setTotalNum(int totalNum) {
		this.totalNum = totalNum;
	}

	@Override
	public String toString() {
		return "Page [pageNo=" + pageNo + ", pageSize=" + pageSize + ", indexNo=" + indexNo + ", list=" + list
				+ ", totalPage=" + totalPage + ", totalNum=" + totalNum + "]";
	}
	
	
	
	

}
